﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

//[RequireComponent(typeof(NavMeshAgent))]
public class DJYD : MonoBehaviour
{
    // Start is called before the first frame update
    NavMeshAgent navMeshAgent;
    RaycastHit raycastHit = new RaycastHit();
    void Start()
    {
        navMeshAgent = GetComponent<NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift))
        {
            var a = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(a.origin, a.direction, out raycastHit))
            {
                navMeshAgent.destination = raycastHit.point;
            }
        }
    }
}
